/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package org.quality4spl.fm.cvm.impl;

import java.util.Collection;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;

import org.eclipse.emf.common.util.EList;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;

import org.eclipse.emf.ecore.impl.ENotificationImpl;

import org.eclipse.emf.ecore.util.EDataTypeUniqueEList;
import org.eclipse.emf.ecore.util.EObjectContainmentEList;
import org.eclipse.emf.ecore.util.InternalEList;

import org.quality4spl.fm.cvm.CvmPackage;
import org.quality4spl.fm.cvm.EntityConfiguration;
import org.quality4spl.fm.cvm.FeatureConfiguration;
import org.quality4spl.fm.cvm.VariableEntity;
import org.quality4spl.fm.cvm.VariableEntityPart;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Entity Configuration</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link org.quality4spl.fm.cvm.impl.EntityConfigurationImpl#getFeatureConfigurations <em>Feature Configurations</em>}</li>
 *   <li>{@link org.quality4spl.fm.cvm.impl.EntityConfigurationImpl#getSubEntityConfigurations <em>Sub Entity Configurations</em>}</li>
 *   <li>{@link org.quality4spl.fm.cvm.impl.EntityConfigurationImpl#getConfiguredEntity <em>Configured Entity</em>}</li>
 *   <li>{@link org.quality4spl.fm.cvm.impl.EntityConfigurationImpl#getConfiguredPart <em>Configured Part</em>}</li>
 *   <li>{@link org.quality4spl.fm.cvm.impl.EntityConfigurationImpl#getSelectedProperties <em>Selected Properties</em>}</li>
 *   <li>{@link org.quality4spl.fm.cvm.impl.EntityConfigurationImpl#getDeselectedProperties <em>Deselected Properties</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class EntityConfigurationImpl extends VariabilityModelEntryImpl implements EntityConfiguration {
	/**
	 * The cached value of the '{@link #getFeatureConfigurations() <em>Feature Configurations</em>}' containment reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getFeatureConfigurations()
	 * @generated
	 * @ordered
	 */
	protected EList<FeatureConfiguration> featureConfigurations;

	/**
	 * The cached value of the '{@link #getSubEntityConfigurations() <em>Sub Entity Configurations</em>}' containment reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getSubEntityConfigurations()
	 * @generated
	 * @ordered
	 */
	protected EList<EntityConfiguration> subEntityConfigurations;

	/**
	 * The cached value of the '{@link #getConfiguredEntity() <em>Configured Entity</em>}' reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getConfiguredEntity()
	 * @generated
	 * @ordered
	 */
	protected VariableEntity configuredEntity;

	/**
	 * The cached value of the '{@link #getConfiguredPart() <em>Configured Part</em>}' reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getConfiguredPart()
	 * @generated
	 * @ordered
	 */
	protected VariableEntityPart configuredPart;

	/**
	 * The cached value of the '{@link #getSelectedProperties() <em>Selected Properties</em>}' attribute list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getSelectedProperties()
	 * @generated
	 * @ordered
	 */
	protected EList<String> selectedProperties;

	/**
	 * The cached value of the '{@link #getDeselectedProperties() <em>Deselected Properties</em>}' attribute list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getDeselectedProperties()
	 * @generated
	 * @ordered
	 */
	protected EList<String> deselectedProperties;

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected EntityConfigurationImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return CvmPackage.Literals.ENTITY_CONFIGURATION;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<FeatureConfiguration> getFeatureConfigurations() {
		if (featureConfigurations == null) {
			featureConfigurations = new EObjectContainmentEList<FeatureConfiguration>(FeatureConfiguration.class, this, CvmPackage.ENTITY_CONFIGURATION__FEATURE_CONFIGURATIONS);
		}
		return featureConfigurations;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<EntityConfiguration> getSubEntityConfigurations() {
		if (subEntityConfigurations == null) {
			subEntityConfigurations = new EObjectContainmentEList<EntityConfiguration>(EntityConfiguration.class, this, CvmPackage.ENTITY_CONFIGURATION__SUB_ENTITY_CONFIGURATIONS);
		}
		return subEntityConfigurations;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public VariableEntity getConfiguredEntity() {
		if (configuredEntity != null && configuredEntity.eIsProxy()) {
			InternalEObject oldConfiguredEntity = (InternalEObject)configuredEntity;
			configuredEntity = (VariableEntity)eResolveProxy(oldConfiguredEntity);
			if (configuredEntity != oldConfiguredEntity) {
				if (eNotificationRequired())
					eNotify(new ENotificationImpl(this, Notification.RESOLVE, CvmPackage.ENTITY_CONFIGURATION__CONFIGURED_ENTITY, oldConfiguredEntity, configuredEntity));
			}
		}
		return configuredEntity;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public VariableEntity basicGetConfiguredEntity() {
		return configuredEntity;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setConfiguredEntity(VariableEntity newConfiguredEntity) {
		VariableEntity oldConfiguredEntity = configuredEntity;
		configuredEntity = newConfiguredEntity;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, CvmPackage.ENTITY_CONFIGURATION__CONFIGURED_ENTITY, oldConfiguredEntity, configuredEntity));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public VariableEntityPart getConfiguredPart() {
		if (configuredPart != null && configuredPart.eIsProxy()) {
			InternalEObject oldConfiguredPart = (InternalEObject)configuredPart;
			configuredPart = (VariableEntityPart)eResolveProxy(oldConfiguredPart);
			if (configuredPart != oldConfiguredPart) {
				if (eNotificationRequired())
					eNotify(new ENotificationImpl(this, Notification.RESOLVE, CvmPackage.ENTITY_CONFIGURATION__CONFIGURED_PART, oldConfiguredPart, configuredPart));
			}
		}
		return configuredPart;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public VariableEntityPart basicGetConfiguredPart() {
		return configuredPart;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setConfiguredPart(VariableEntityPart newConfiguredPart) {
		VariableEntityPart oldConfiguredPart = configuredPart;
		configuredPart = newConfiguredPart;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, CvmPackage.ENTITY_CONFIGURATION__CONFIGURED_PART, oldConfiguredPart, configuredPart));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<String> getSelectedProperties() {
		if (selectedProperties == null) {
			selectedProperties = new EDataTypeUniqueEList<String>(String.class, this, CvmPackage.ENTITY_CONFIGURATION__SELECTED_PROPERTIES);
		}
		return selectedProperties;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<String> getDeselectedProperties() {
		if (deselectedProperties == null) {
			deselectedProperties = new EDataTypeUniqueEList<String>(String.class, this, CvmPackage.ENTITY_CONFIGURATION__DESELECTED_PROPERTIES);
		}
		return deselectedProperties;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case CvmPackage.ENTITY_CONFIGURATION__FEATURE_CONFIGURATIONS:
				return ((InternalEList<?>)getFeatureConfigurations()).basicRemove(otherEnd, msgs);
			case CvmPackage.ENTITY_CONFIGURATION__SUB_ENTITY_CONFIGURATIONS:
				return ((InternalEList<?>)getSubEntityConfigurations()).basicRemove(otherEnd, msgs);
		}
		return super.eInverseRemove(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
			case CvmPackage.ENTITY_CONFIGURATION__FEATURE_CONFIGURATIONS:
				return getFeatureConfigurations();
			case CvmPackage.ENTITY_CONFIGURATION__SUB_ENTITY_CONFIGURATIONS:
				return getSubEntityConfigurations();
			case CvmPackage.ENTITY_CONFIGURATION__CONFIGURED_ENTITY:
				if (resolve) return getConfiguredEntity();
				return basicGetConfiguredEntity();
			case CvmPackage.ENTITY_CONFIGURATION__CONFIGURED_PART:
				if (resolve) return getConfiguredPart();
				return basicGetConfiguredPart();
			case CvmPackage.ENTITY_CONFIGURATION__SELECTED_PROPERTIES:
				return getSelectedProperties();
			case CvmPackage.ENTITY_CONFIGURATION__DESELECTED_PROPERTIES:
				return getDeselectedProperties();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@SuppressWarnings("unchecked")
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
			case CvmPackage.ENTITY_CONFIGURATION__FEATURE_CONFIGURATIONS:
				getFeatureConfigurations().clear();
				getFeatureConfigurations().addAll((Collection<? extends FeatureConfiguration>)newValue);
				return;
			case CvmPackage.ENTITY_CONFIGURATION__SUB_ENTITY_CONFIGURATIONS:
				getSubEntityConfigurations().clear();
				getSubEntityConfigurations().addAll((Collection<? extends EntityConfiguration>)newValue);
				return;
			case CvmPackage.ENTITY_CONFIGURATION__CONFIGURED_ENTITY:
				setConfiguredEntity((VariableEntity)newValue);
				return;
			case CvmPackage.ENTITY_CONFIGURATION__CONFIGURED_PART:
				setConfiguredPart((VariableEntityPart)newValue);
				return;
			case CvmPackage.ENTITY_CONFIGURATION__SELECTED_PROPERTIES:
				getSelectedProperties().clear();
				getSelectedProperties().addAll((Collection<? extends String>)newValue);
				return;
			case CvmPackage.ENTITY_CONFIGURATION__DESELECTED_PROPERTIES:
				getDeselectedProperties().clear();
				getDeselectedProperties().addAll((Collection<? extends String>)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case CvmPackage.ENTITY_CONFIGURATION__FEATURE_CONFIGURATIONS:
				getFeatureConfigurations().clear();
				return;
			case CvmPackage.ENTITY_CONFIGURATION__SUB_ENTITY_CONFIGURATIONS:
				getSubEntityConfigurations().clear();
				return;
			case CvmPackage.ENTITY_CONFIGURATION__CONFIGURED_ENTITY:
				setConfiguredEntity((VariableEntity)null);
				return;
			case CvmPackage.ENTITY_CONFIGURATION__CONFIGURED_PART:
				setConfiguredPart((VariableEntityPart)null);
				return;
			case CvmPackage.ENTITY_CONFIGURATION__SELECTED_PROPERTIES:
				getSelectedProperties().clear();
				return;
			case CvmPackage.ENTITY_CONFIGURATION__DESELECTED_PROPERTIES:
				getDeselectedProperties().clear();
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case CvmPackage.ENTITY_CONFIGURATION__FEATURE_CONFIGURATIONS:
				return featureConfigurations != null && !featureConfigurations.isEmpty();
			case CvmPackage.ENTITY_CONFIGURATION__SUB_ENTITY_CONFIGURATIONS:
				return subEntityConfigurations != null && !subEntityConfigurations.isEmpty();
			case CvmPackage.ENTITY_CONFIGURATION__CONFIGURED_ENTITY:
				return configuredEntity != null;
			case CvmPackage.ENTITY_CONFIGURATION__CONFIGURED_PART:
				return configuredPart != null;
			case CvmPackage.ENTITY_CONFIGURATION__SELECTED_PROPERTIES:
				return selectedProperties != null && !selectedProperties.isEmpty();
			case CvmPackage.ENTITY_CONFIGURATION__DESELECTED_PROPERTIES:
				return deselectedProperties != null && !deselectedProperties.isEmpty();
		}
		return super.eIsSet(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public String toString() {
		if (eIsProxy()) return super.toString();

		StringBuffer result = new StringBuffer(super.toString());
		result.append(" (selectedProperties: ");
		result.append(selectedProperties);
		result.append(", deselectedProperties: ");
		result.append(deselectedProperties);
		result.append(')');
		return result.toString();
	}

} //EntityConfigurationImpl
